<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>问卷列表-默问台</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="/assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <script src="/assets/js/echarts.min.js"></script>
    <link rel="stylesheet" href="/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="/assets/css/amazeui.datatables.min.css" />
    <link rel="stylesheet" href="/assets/css/app.css">
    <script src="/assets/js/jquery.min.js"></script>

</head>

<iframe name="Upframe" id="Upframe" style="display: none" ></iframe>

<body data-type="index">
    <script src="/assets/js/theme.js"></script>
    <div class="am-g tpl-g">
        <!-- 头部 -->
        <header>
            <!-- logo -->
            <div class="am-fl tpl-header-logo">
            </div>
            <!-- 右侧内容 -->
            <div class="tpl-header-fluid">
                <!-- 侧边切换 -->
               
                <!-- 搜索 -->
                
                <!-- 其它功能-->
                <div class="am-fr tpl-header-navbar">
                    <ul>
                        <!-- 欢迎语 -->
                        <li class="am-text-sm tpl-header-navbar-welcome">
                            <a href="javascript:;">欢迎你, <span>admin</span> </a>
                        </li>

                        <!-- 新邮件 -->

                        <!-- 新提示 -->


                        <!-- 退出 -->
                        <li class="am-text-sm">
                            <a href="javascript:;">
                                <span class="am-icon-sign-out"></span> 退出
                            </a>
                        </li>
                    </ul>
                </div>
            </div>

        </header>
        <!-- 风格切换 -->
        
        <!-- 侧边导航栏 -->
        <div class="left-sidebar">
            <!-- 用户信息 -->


            <!-- 菜单 -->
            <ul class="sidebar-nav">

                <li class="sidebar-nav-link">
                    <a href="/bo/toHome" >
                        <i class="am-icon-home sidebar-nav-link-logo"></i>问卷管理
                    </a>
                </li>

                <li class="sidebar-nav-link">
                    <a href="/bo/toGood" >
                        <i class="am-icon-home sidebar-nav-link-logo"></i>商品管理
                    </a>
                </li>

                <li class="sidebar-nav-link">
                    <a href="/bo/toOrder" class="active">
                        <i class="am-icon-home sidebar-nav-link-logo"></i>订单管理
                    </a>
                </li>

            </ul>
        </div>


        <!-- 内容区域 -->
        <div class="tpl-content-wrapper">

            <div class="row-content am-cf">
                <span style="color:#fff">订单管理</span>
                <div class="row  am-cf">
                    <form id="goodForm" target="Upframe" method="post" class="am-form tpl-form-line-form" enctype="multipart/form-data">

                    </form>
                    
                </div>



                <div class="widget-body  widget-body-lg am-fr">

                    <div class="am-form-group">
                        <div class="am-u-sm-9 am-u-sm-push-3">
                            <select id="status" onchange="listOrders();">
                                <option value="-1" selected>全部</option>
                                <option value="0">待发货</option>
                                <option value="1">已发货</option>
                                <option value="2">取消</option>
                            </select>
                        </div>
                    </div><br><br>

                    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                        <thead>
                        <tr>
                            <th>订单ID</th>
                            <th>商品图片</th>
                            <th>商品名称</th>
                            <th>单价</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="tableDiv">
                        <!-- more data -->
                        </tbody>
                    </table>

                    <ul class="am-pagination">
                        <li><a href="###" onclick="first();">首页 &raquo;</a></li>
                        <li><a href="###" onclick="pre();">&laquo; 上一页</a></li>
                        <li><a href="###" onclick="next();">下一页 &raquo;</a></li>
                        <li><a href="###" onclick="last();">尾页 &raquo;</a></li>
                        <li id="pageInfo">1/1
                        </li>
                    </ul>



                </div>

            </div>
        </div>
    </div>
    </div>
    <script src="/assets/js/amazeui.min.js"></script>
    <script src="/assets/js/amazeui.datatables.min.js"></script>
    <script src="/assets/js/dataTables.responsive.min.js"></script>
    <script src="/assets/js/app.js"></script>

<script>

    var currnetPage = 1;
    var totalPage = 1;

    $(document).ready(function () {
        listOrders();
    });

    function  next() {
        if (currnetPage >= totalPage) {
            return;
        }

        currnetPage ++;

        listOrders();
    }

    function  pre() {
        if (currnetPage <= 1) {
            return;
        }

        currnetPage --;

        listOrders();
    }

    function first() {
        if (currnetPage === 1) {
            return;
        }

        currnetPage = 1;

        listOrders();
    }

    function last() {
        if (currnetPage === totalPage) {
            return;
        }

        currnetPage = totalPage;
        listOrders();
    }

    function listOrders() {
        $.ajax({
            url: '/bo/order/list',
            type: 'POST', //GET
            async: true,    //或false,是否异步
            data: {
                status : $('#status').val(),
                currentPage : currnetPage
            },
            timeout: 10000,    //超时时间
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            success: function (ajaxData, textStatus, jqXHR) {
                if (ajaxData.code !== 1000) {
                    alert(ajaxData.message);
                    return;
                }

                var result = ajaxData.data.data;
                var msg = '';
                for (var i=0;i<result.length;i++) {
                    msg += '<tr class="gradeX">';
                    msg += '<td>'+result[i].orderId+'</td>';
                    msg += '<td><img width="50px" height="50px" src="'+result[i].picUrl+'"></td>';
                    msg += '<td>'+result[i].goodName+'</td>';
                    msg += '<td>'+result[i].amount+'</td>';
                    msg += '<td>'+result[i].statusDesc+'</td>';
                    msg += '<td><a href="###" onclick="changStatus('+result[i].orderId+',1)">发货</a>&nbsp;&nbsp;<a href="###" onclick="changStatus('+result[i].orderId+', 2)">取消</a>&nbsp;&nbsp;</td>';
                }

                totalPage = ajaxData.data.totalPage;
                $('#pageInfo').html(currnetPage + '/' + totalPage);
                $('#tableDiv').html(msg);
            }
        });
    }


    function changStatus(id, status) {
        $.ajax({
            url: '/bo/order/changeStatus',
            type: 'POST', //GET
            async: true,    //或false,是否异步
            data: {
                orderId:id,
                status:status
            },
            timeout: 10000,    //超时时间
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            success: function (ajaxData, textStatus, jqXHR) {
                if (ajaxData.code !== 1000) {
                    alert(ajaxData.message);
                    return;
                }

                listOrders();

                alert('修改成功');

            }
        });
    }

</script>

</body>

</html>